﻿using Company.Application.Setting.Models;
using Company.Application.Setting.Services;
using Company.Application.Share.Config;
using Company.Core.Dialogs;
using Company.Core.Enums;
using Company.Core.Helpers;
using Company.Core.IOC;
using Company.Core.Language;
using Company.Hardware.Camera;
using Company.Hardware.Detector;
using Prism.Commands;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace Company.Application.Setting.ViewModels
{
    public class SettingViewModel : DialogViewModelBase
    {
        private readonly SettingManager _settingManager;
        private readonly SettingProvider _settingProvider;
        public SettingViewModel(SettingManager settingManager, SettingProvider settingProvider)
        {
            _settingManager = settingManager;
            _settingProvider = settingProvider;
            Title = "系统设置";
            OKCommand = ReactiveCommand.Create(DoOK);
        }

        public SettingModel Config => _settingManager.Config;

        public ICommand OKCommand { get; }

        public ICommand CancelCommand { get; }

        private void DoOK()
        {
            _settingManager.Save(); // 参数持久化
            _settingProvider.Invoke(); // 通知硬件重新初始化
            CloseDialog(Prism.Services.Dialogs.ButtonResult.OK);
        }
    }
}
